package com.linkage.bookshop.authentication;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;
import org.springframework.security.authentication.*;

@Component
public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler{

	@Override
	public void onAuthenticationFailure(HttpServletRequest request,HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
		if(exception instanceof LockedException){
			request.setAttribute("status","账户被封,请联系管理员");
		}else{
			request.setAttribute("status","用户名或密码错误");
		}
		request.getRequestDispatcher("/login.jsp").forward(request, response);
	}

}
